package com.example.yls.demoa;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class QuerryActivity extends AppCompatActivity {
    private EditText edtNo;
    private Button btnSearch;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_querry);

        edtNo = findViewById(R.id.edt_no);
        btnSearch = findViewById(R.id.btn_search);
        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            querrysss();

            }
        });
    }

    private void querrysss() {
        MyDataBaseHelper helper = new MyDataBaseHelper(QuerryActivity.this);
        SQLiteDatabase db = helper.getReadableDatabase();

        String where = "no="+edtNo.getText().toString();

        Cursor cur = db.query("student",
                null,
                where,
                null,
                null,
                null,null);
        cur.moveToFirst();
        String name = cur.getString(2);
        String birth = cur.getString(3);
        String phone  = cur.getString(4);

        Intent intent = new Intent();
        intent.putExtra("NO", edtNo.getText().toString());
        intent.putExtra("NAME", name);
        intent.putExtra("BIRTH", birth);
        intent.putExtra("PHONE", phone);
        intent.setClass(QuerryActivity.this, ShowStudentActivity.class);
        startActivity(intent);
    }
}
